//处理点击事件的延时问题
var scriptCom = document.createElement("script");
scriptCom.src = 'js/fastclick.js';
document.getElementsByTagName("head")[0].appendChild(scriptCom);
document.addEventListener('DOMContentLoaded', function() {
    setTimeout(function() {
        FastClick.attach(document.body);
        document.querySelector('body').addEventListener('click',function(ev){
			if(ev.target.nodeName.toLowerCase()=='input'){
				ev.target.focus();
			}
		});
    }, 200);
}, false);

//验证手机号正则
var _checkMobile = function(sMobile) {
    if (!(/^1[3|4|5|6|7|8|9][0-9]\d{8}$/.test(sMobile))) {
        return false;
    } else {
        return true;
    }
}

//转换时间戳
var _date = function(timestamp) {
    if (!timestamp) {
        return "";
    }
    var date;
    //时间戳为10位需*1000，时间戳为13位的话不需乘1000
    if (String(timestamp).length == 10) {
        date = new Date(Number(timestamp) * 1000);
    }
    if (String(timestamp).length == 13) {
        date = new Date(Number(timestamp));
    }
    var Y = date.getFullYear() + "-";
    var M =
        (date.getMonth() + 1 < 10 ?
            "0" + (date.getMonth() + 1) :
            date.getMonth() + 1) + "-";
    var D = date.getDate() + " ";
    var h = date.getHours() + ":";
    if (date.getHours() < 10) {
        h = '0' + date.getHours() + ":";
    }
    var m = date.getMinutes() + ":";
    if (date.getMinutes() < 10) {
        m = '0' + date.getMinutes() + ":";
    }
    var s = date.getSeconds();
    if (date.getSeconds() < 10) {
        s = '0' + date.getSeconds();
    }
    return Y + M + D + h + m + s;
};
//关闭页面
var _close = function() {
    var web = plus.webview.currentWebview();
    web.close('none');
};
//乘法
var _accMul = function(arg1, arg2) {
    var m = 0,
        s1 = arg1.toString(),
        s2 = arg2.toString();
    try { m += s1.split(".")[1].length } catch (e) {}
    try { m += s2.split(".")[1].length } catch (e) {}
    return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m)
};
//钱分转换为元
var _money = function(val) {
    var judge = String(val);
    if (judge == "undefined" || judge == "null") {
        return 0.0;
    }
    var priceStr = String(parseFloat(parseInt(val) / 100));
    var index = priceStr.indexOf(".");
    if (index != -1) {
        var handle = priceStr.slice(index + 1);
        if (handle.length == 1) {
            priceStr = priceStr + "0";
        }
    } else {
        priceStr = priceStr + ".00";
    }
    return priceStr;
};
/*
	content:密码错误(提示内容)
	position:center(提示的垂直位置)
*/
var _toast = function(content, position) {
    if (!position) {
        position = 'center';
    }
    plus.nativeUI.toast(content, {
        verticalAlign: position
    });
};

// 复制到剪贴板
var _copy = function(text) {
    var osName = plus.os.name;
    if (plus.os.name == "Android") {
        var Context = plus.android.importClass("android.content.Context");
        var main = plus.android.runtimeMainActivity();
        var clip = main.getSystemService(Context.CLIPBOARD_SERVICE);
        plus.android.invoke(clip, "setText", text);
    } else if (osName == "iOS") {
        var UIPasteboard = plus.ios.importClass("UIPasteboard");
        var generalPasteboard = UIPasteboard.generalPasteboard();
        // 设置/获取文本内容:
        generalPasteboard.setValueforPasteboardType(text, "public.utf8-plain-text");
    }
};

//截取6位
var _toFixed = function(str1, num) {
    var str = String(str1);

    function hanZeo(z) {
        var zeo = '';
        for (var i = 0; i < z; i++) {
            zeo += '0';
        }
        return zeo;
    }
    var arr = str.split('.');
    if (arr[1]) {
        if (arr[1].length >= num) {
            return arr[0] + '.' + arr[1].slice(0, num);
        } else {
            return arr[0] + '.' + arr[1] + hanZeo(num - arr[1].length);
        }
    } else {
        return str + '.' + hanZeo(num);
    }
};

//判断输入的是小数或整数
var _ifNum = function(val, type) {
    // 返回true:满足   false:不满足
    // type:int/float
    if (!parseFloat(val)) {
        return false;
    }
    var str = String(val);
    var point = 0;
    var off = true;
    for (var i = 0; i < str.length; i++) {
        if (isNaN(Number(str[i]))) {
            //不是数字
            if (str[i] == '.') {
                point++;
            } else {
                off = false;
                break;
            }
        }
    }
    if (type == 'int') {
        (off && !point) ? '' : off = false;
    }
    if (type == 'float') {
        (off && point <= 1 && str[str.length - 1] != '.' && str[0] != '.') ? '' : off = false;
    }
    return off;
};

//关闭除index的其他页面
var _clsoeOther = function() {
    function plusReady() {
        var index = plus.webview.getWebviewById('index');
        if (!index) {
            index = _openHref('index.html', 'index', 'none');
        }
        var all = plus.webview.all();
        var indexUrl = index.getURL();
        for (var i = 0; i < all.length; i++) {
            if (all[i].getURL() != indexUrl) {
                all[i].hide();
            }
        }
        setTimeout(function() {
            for (var i = 0; i < all.length; i++) {
                if (all[i].getURL() != indexUrl) {
                    all[i].close('none');
                }
            }
        }, 1500);
    }
    // 判断扩展API是否准备，否则监听'plusready'事件
    if (window.plus) {
        plusReady();
    } else {
        document.addEventListener('plusready', plusReady, false);
    }
};

var _bas64Post = function(url, json, cal) {
    function handleBase64(data) {
        console.log('原没加密的json========');
        console.log(JSON.stringify(data));
        var base = new Base64();
        var list = {};
        for (var key in data) {
            var val = null;
            if (typeof data[key] == 'object' || typeof data[key] == 'number') {
                val = JSON.stringify(data[key]);
            } else {
                val = data[key];
            }
            list[base.encode(key)] = base.encode(val);
        }
        return list;
    }
    _post(url, handleBase64(json), cal);
};

var _post = function(url, json, cal) {
    console.log('url++++++' + url);
    console.log('post参数+++++++++');
    console.log(JSON.stringify(json));
    var obj = new XMLHttpRequest();
    obj.open('post', url, true);
    obj.onreadystatechange = function() {
        if (obj.readyState == 4 && obj.status == 200 || obj.status == 304) {
            switch (obj.responseText) {
                case '本接口需要传递参数':
                case '本接口需要传递用户参数':
                case 'session无效':
                    _toast(obj.responseText);
                    setTimeout(function() {
                        plus.webview.currentWebview().close('none');
                    }, 1000);
                    break;
                default:
                    var ret = JSON.parse(obj.responseText);
                    console.log('post返回的结果++++++');
                    console.log(JSON.stringify(ret));
                    cal(ret);
            }
        }
    };
    obj.send(JSON.stringify(json));
}

//打开页面
var _openHref = function(json) {
    var animate = json.animate ? json.animate : 'slide-in-right';
    var op = {
        'backButtonAutoControl': 'close', //返回是关闭当前页
        'animationOptimization': 'none', //不优化
        statusbar: {
            background: json.bg ? json.bg : '#2a2c35'
        }
    };
    if (plus.os.name.toLowerCase() == 'android' && parseFloat(plus.os.version) < 6) {
        //手机不行的就别开启硬件加速了
        op.hardwareAccelerated = json.spe ? json.spe : false;
    }
    var web = plus.webview.getWebviewById(json.id);
    if (web) {
        web.show();
    } else {
        app.$data.jiazai = true;
        web = plus.webview.create(json.url, json.id, op);
        web.addEventListener("loaded", function() {
            setTimeout(function() {
                app.$data.jiazai = false;
                web.show(animate);
            }, 200);
        }, false);
    }
    return web;
}

//正式
var HTTP='http://cc.dayunkong.com';

var HTTP_UPDATE="http://new.dayunkong.com";

//测试
//var HTTP='http://cc.k1m.cn';

//登陆
var LOGIN = HTTP + '/manage/login';

//注册
var REGIST = HTTP + '/manage/register';

//APP首页
var APP_INDEX = HTTP + '/Appindex/index';

//充值頁面
var CHONZHI_INDEX = HTTP + '/manage/recharge';

//定期页
var DINQI_INDEX = HTTP + '/Appindex/regular';

//邀请页
var INVI = HTTP + '/Appindex/friend';

//我的页
var MY_INDEX = HTTP + '/manage/index';

//存定期页面
var CUN_DINQI = HTTP + '/Appindex/gotoregular';

//定期的立即存入
var CUN_DATA = HTTP + '/Appindex/toregular';

//定期返利页面
var DIN_FAN = HTTP + '/Appindex/regular_view';

//定期返利记录
var DIN_FAN_JIES = HTTP + '/Appindex/regular_lock';

//会员中心
var USER_INDEX = HTTP + '/manage/index';

//公共账单列表
var BILL_LIST = HTTP + '/manage/billlist';

//账单详情
var BILL_INFO = HTTP + '/manage/bill_view';

//修改登陆密码
var EDIT_LOGIN_PAS = HTTP + '/manage/upd_pwd';

//修改交易密码 
var EDIT_TRANS_PAS = HTTP + '/manage/upd_pin';

//提现接口
var TIXIAN_PAY = HTTP + '/manage/transfer_to';

//提现页面
var TIXIAN_INDEX = HTTP + '/manage/transfer';

//版本更新
var UPDATA = HTTP_UPDATE + '/Appindex/game_update';

//市场
var SHICHANG = HTTP + '/manage/market';

//余额转活期
var TRAN_IN = HTTP + '/Appindex/todemand';

//余额转活期拿余额
var TRAN_IN_GET = HTTP + '/Appindex/godemand';

//活期转余额
var TRAN_OUT = HTTP + '/Appindex/demandto';

//活期转余额拿余额
var TRAN_OUT_GET = HTTP + '/Appindex/godemandto';

//活期空投列表
var HUO_KON = HTTP + '/Appindex/airdroplist';

//活期空投详情
var HUO_KON_INFO = HTTP + '/Appindex/airdropview';

//获取文章
var GET_ARI = HTTP + '/Appindex/get_news';

//发短信接口
var DUANXIN = HTTP + '/Appindex/juhe_sms';

//处理封号
var FRO_ZEN = HTTP + '/manage/is_frozen';

//滑块验证
var SLIDER = HTTP + '/manage/slider';

//会员人数
var USER_COUNT = HTTP + '/manage/app_entrance';

//公告
var GO_GAO = HTTP + '/Appindex/gogao';

//传身份证图片
var ID_CARD_IMG=HTTP+'/manage/po_upload';

//实名认证接口
var AUTHER_SUB=HTTP+'/manage/realcertification';

//实名认证接口  重新传正反面图片
var AUTHER_SUB2=HTTP+'/manage/realcertification2';
